<template>
  <div>
    <TitleName
      class="title"
      icon="i-carbon-bookmark-filled"
      title="合同信息"
    ></TitleName>
    <el-table :data="contractTableList" border class="mt-15px">
      <el-table-column
        :show-overflow-tooltip="true"
        label="合同名称"
        prop="contractName"
      >
      </el-table-column>
      <el-table-column key="businessType" label="业务属性" width="100">
        <template #default="scope">
          <dict-tag
            :isTag="false"
            :options="business_attribute"
            :value="scope.row.businessType"
          />
        </template>
      </el-table-column>
      <el-table-column key="status" label="合同状态" width="120">
        <template #default="scope">
          <dict-tag
            :isTag="false"
            :options="contract_status"
            :value="scope.row.status"
          />
        </template>
      </el-table-column>
      <el-table-column label="签署人" prop="partybSig" width="120" />
      <el-table-column label="有效时间范围" width="220">
        <template #default="scope">
          <span
            >{{ parseTime(scope.row.contractTimeBegin, '{y}-{m}-{d}') }}至{{
              parseTime(scope.row.contractTimeEnd, '{y}-{m}-{d}')
            }}</span
          >
        </template>
      </el-table-column>
      <el-table-column label="签署时间" prop="sinTime" width="110">
        <template #default="scope">
          <span>{{ parseTime(scope.row.sinTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="120">
        <template #default="scope">
          <el-button
            link
            size="small"
            type="primary"
            @click="handleDetails(scope.row)"
            >详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script name="ProjectContract" setup>
import { getCurrentInstance } from 'vue'
import { useRouter } from 'vue-router'
import { contractInfoListNoPriv } from '@/api/salesManage/contractManage' //关联合同接口
import {
  business_attribute, //业务属性
  contract_status
} from '@/hooks/dict/useProject'
const router = useRouter()
const { proxy } = getCurrentInstance()
// 接受父级传递的参数
const props = defineProps({
  tableParam: {
    type: Object
  }
})

const data = reactive({
  queryForm: {
    pageNum: 1,
    pageSize: 99999
  },
  // 合同信息
  contractTableList: []
})
const { queryForm, contractTableList } = toRefs(data)
async function getList() {
  let param = JSON.parse(JSON.stringify(queryForm.value))
  await contractInfoListNoPriv(param).then(response => {
    if (response.code == 200) {
      contractTableList.value = response.data.records
    }
  })
}
async function init() {
  queryForm.value = { ...queryForm.value, ...props.tableParam }
  console.log('queryForm.value', queryForm.value)
  await getList()
}
// init()

onMounted(() => {
  if (JSON.stringify(props.tableParam) != '{}') {
    console.log('props.taskParam', props.tableParam)
    init()
  } else {
    init()
  }
})
// 详情
const handleDetails = row => {
  router.push({
    path: '/sales/contract/contractDetail',
    query: { id: row.rcId }
  })
}
</script>

<style lang="scss" scoped></style>
